import 'package:flutter/material.dart';

void main() {
  runApp(MainApp());
}

class MyChildPage extends StatefulWidget {
  final MyState state;
  const MyChildPage({required this.state, super.key});

  @override
  State<MyChildPage> createState() => _MyChildPageState();
}

class _MyChildPageState extends State<MyChildPage> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          Text('Child Page ${widget.state.count}'),
          Text('double count ${widget.state.doubleCount}'),
          ElevatedButton(
              child: const Text('child page increment'),
              onPressed: () {
                setState(() {
                  widget.state.count++;
                });
              })
        ],
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class MyState {
  int _count = 0;
  int get count => _count;
  set count(int value) {
    _count = value;
  }

  int get doubleCount => _count * 2;
}

class _MyHomePageState extends State<MyHomePage> {
  final MyState state = MyState();
  _incrementCount() {
    setState(() {
      state.count++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('helli kitty count ${state.count}'),
            Text('double count ${state.doubleCount}'),
            ElevatedButton(
                onPressed: _incrementCount, child: const Text('Increment')),
            MyChildPage(
              state: state,
            )
          ],
        ),
      ),
    );
  }
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}
